package com.apes.hr.salary.rewardPunish.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.plugin.fileserver.File;
import com.apes.hr.base.model.Employee;
import com.apes.scm.masterdata.party.model.PartyRole;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * 功能：处惩申诉
 * @author HuJianlin
 * @create 2018-05-05 15:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PunishAppeal.CONST_TABLE_NAME)
public class PunishAppeal extends Model {
    public static final String CONST_TABLE_NAME = "hr_punish_appeal";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "处惩申诉", padding = 4)
    @Comment("处惩申诉单号")
    private String id;   //处惩申诉单号

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "Employee_id", referencedColumnName = "ID")
    @Comment("员工")
    private Employee employee;   //员工

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "reward_punish_id", referencedColumnName = "id")
    @Comment("奖罚单号")
    private RewardPunish rewardPunish; //奖罚单号

    @Column(name = "appeal", length = 1000)
    @Comment("诉求")
    private String appeal;    //诉求

    @Column(name = "reason", length = 1000)
    @Comment("申诉原因")
    private String reason;    //申诉原因

    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "proof_img",columnDefinition = "CLOB")
    @Comment("证据图片")
    private String proofImg;   //证据图片


    @File
    @Lob
    @Basic(fetch = FetchType.LAZY)
    @Column(name = "proof_attachments",columnDefinition = "CLOB")
    @Comment("附件")
    private String proofAttachments;   //附件

    @Column(name = "state", length = 10, nullable = false)
    @Comment("状态")
    private String state; //状态： ('sent', '提交'), ('done', '已审核')

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "approve_uid", referencedColumnName = "id")
    @Comment("审批人")
    private PartyRole approveUid; //审批人

    @Column(name = "approve_date")
    @Comment("审批日期")
    private Date approveDate; //审批日期

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cancel_uid", referencedColumnName = "id")
    @Comment("作废人")
    private PartyRole cancelUid; //作废人

    @Column(name = "cancel_date")
    @Comment("作废日期")
    private Date cancelDate; //作废日期

}
